/*
    This file is part of Epoch <http://code.google.com/p/epoch/>.
    
    Copyright (C) 2011  Adam Meily <meily.adam@gmail.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#ifndef MESSAGE_H
#define MESSAGE_H
#include <QtCore/QString>
#include <QtCore/QMap>
#include <QtCore/QStringList>

typedef QMap<QString, QString> Record;
typedef QMapIterator<QString, QString> RecordFieldIterator;

class Message
{
public:
    Message();
    Message(const Message& other);
    virtual ~Message();
    Message& operator=(const Message& other);
    
    /*
    enum Mode //MessageMode
    {
        HeaderOnly = 0x01,
        SingleRecord = 0x05,
        MultiRecords = 0x09,
        BinaryData = 0x02
    };
    */
    //Q_DECLARE_FLAGS(Mode, MessageMode);
    
    //const QString& id() const;
    const QString& operation() const;
    virtual bool isNull() const = 0;
    
    const Record& args() const;
    void args(const Record& args);
    void addArg(const QString& key, const QString& value);
    
    //int nextRecord();
    //bool hasNextRecord() const;
    //const Record& record() const;
    void addRecord(const Record& record);
    const QList<Record>& records() const;
    QListIterator<Record> recordIterator() const;
    //int recordCount() const;
    
    //Mode mode() const;
    //void mode(Mode mode);
    
    //static Message parse(const QStringList& input);
    
protected:
    Message(const QStringList& input);
    void operation(const QString& op);
    
    //Record& record();
    Record& args();
    //void id(const QString& id);
    //void genid();
    QString prepareInput(const QString& input) const;
    Record parseRecord(const QString& input) const;
    //Mode parseMode(const QString& input) const;
    
private:
    static Record NullRecord;
    //void setMode(Mode mode);
    //Mode m_mode;
    Record m_args;
    QString m_operation;
    //int m_recordIndex;
    QList<Record> m_records;
    //QString m_id;
};

//Q_DECLARE_FLAG_OPERATIONS(Message::Mode);
#endif // MESSAGE_H
